package com.test.ddaidai_android.register;

import com.test.ddaidai.BaseActivity;
import com.test.ddaidai_android.activity.R;
import com.test.widget.ValidateImageView;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class RegisterActivity extends BaseActivity implements OnClickListener {

	Button btn_lgin;
	ValidateImageView view_regist_validatecode;
	String[] responseArray = null;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		

		setContentView(R.layout.activity_register);

		setTitle(getString(R.string.register_message),
				R.string.login_header_tv_left,true, R.string.register_header_tv_right,true);
		view_regist_validatecode = (ValidateImageView) findViewById(R.id.view_regist_validatecode);
		view_regist_validatecode.setOnClickListener(this);
		responseArray = view_regist_validatecode.getValidataAndSetImage(getRandomInteger());
//		Toast.makeText(this, getResponseStr(responseArray), 2000).show();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.view_regist_validatecode:
			responseArray = view_regist_validatecode.getValidataAndSetImage(getRandomInteger());
//			Toast.makeText(this, getResponseStr(responseArray), 2000).show();
			break;

		default:
			break;
		}
	}

	//为数组赋值1~9的随机数
	private String[] getRandomInteger(){
		String[] reuestArray = new String[4];
		for(int i = 0 ; i < 4 ; i++){
			reuestArray[i] = String.valueOf((int)(Math.random()*9+1));
		}
		return reuestArray;
	}
	//获取返回的数组
	private String getResponseStr(String[] response){
		StringBuffer stringBuffer = new StringBuffer();
		for(String str : response){
			stringBuffer.append(str);
		}
		return stringBuffer.toString();
	}


}
